// pagesMine/pages/invitation/invitation.js
import ajax from "../../../utils/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    qrCode: null,
    codeNumber: '32132',
    userInfo: null,
    formData: {
      id: 1,
      page: "pages/index/index",
      shareId: 0
    }
  },
  copyEvent() {
    wx.setClipboardData({
      data: this.data.userInfo.invitationCode,
      success: () => wx.getClipboardData({ success: (res) => res.data ? wx.showToast({ title: '复制成功' }) : null })
    })
  },
  saveEvent() {
    wx.saveImageToPhotosAlbum({
      filePath: this.data.qrCode,
      success(res) {
        wx.showToast({
          title: '保存图片成功！',
        })
      },
    })
  },
  async getQrCode() {
    const res = await ajax.getQrCode(this.data.formData)
    this.setData({ qrCode: res })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const userInfo = wx.getStorageSync('userInfo')
    this.setData({userInfo})
    this.data.formData.shareId = userInfo.id
    this.getQrCode()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const userInfo = wx.getStorageSync('userInfo')
    return {
      title: `${userInfo.nickName}邀请加入易单配`,
      imageUrl: 'https://file.yledanpei.com/2021/10/21/83c33df3-468c-4cbd-931a-9cc3ae60643a.png',
      path: `/pages/index/indexs?shareId=${userInfo.id}`
    }
    
  }
})